package com.ruoyi.webshop.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.webshop.domain.CategoryBrand;
import com.ruoyi.webshop.mapper.CategoryBrandMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.webshop.mapper.BrandInfoMapper;
import com.ruoyi.webshop.domain.BrandInfo;
import com.ruoyi.webshop.service.IBrandInfoService;

/**
 * 品牌#brand_infoService业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-14
 */
@Service
public class BrandInfoServiceImpl implements IBrandInfoService 
{
    @Autowired
    private BrandInfoMapper brandInfoMapper;

    @Autowired
    private CategoryBrandMapper categoryBrandMapper;

    /**
     * 查询品牌#brand_info
     * 
     * @param brandId 品牌#brand_info主键
     * @return 品牌#brand_info
     */
    @Override
    public BrandInfo selectBrandInfoByBrandId(Long brandId)
    {
        return brandInfoMapper.selectBrandInfoByBrandId(brandId);
    }

    /**
     * 查询品牌#brand_info列表
     * 
     * @param brandInfo 品牌#brand_info
     * @return 品牌#brand_info
     */
    @Override
    public List<BrandInfo> selectBrandInfoList(BrandInfo brandInfo)
    {
        return brandInfoMapper.selectBrandInfoList(brandInfo);
    }

    /**
     * 新增品牌#brand_info
     * 
     * @param brandInfo 品牌#brand_info
     * @return 结果
     */
    @Override
    public int insertBrandInfo(BrandInfo brandInfo)
    {
        brandInfo.setCreateTime(DateUtils.getNowDate());
        return brandInfoMapper.insertBrandInfo(brandInfo);
    }

    /**
     * 修改品牌#brand_info
     * 
     * @param brandInfo 品牌#brand_info
     * @return 结果
     */
    @Override
    public int updateBrandInfo(BrandInfo brandInfo)
    {
        brandInfo.setUpdateTime(DateUtils.getNowDate());
        return brandInfoMapper.updateBrandInfo(brandInfo);
    }

    /**
     * 批量删除品牌#brand_info
     * 
     * @param brandIds 需要删除的品牌#brand_info主键
     * @return 结果
     */
    @Override
    public int deleteBrandInfoByBrandIds(Long[] brandIds)
    {
        return brandInfoMapper.deleteBrandInfoByBrandIds(brandIds);
    }

    /**
     * 删除品牌#brand_info信息
     * 
     * @param brandId 品牌#brand_info主键
     * @return 结果
     */
    @Override
    public int deleteBrandInfoByBrandId(Long brandId)
    {
        return brandInfoMapper.deleteBrandInfoByBrandId(brandId);
    }

    @Override
    public List<BrandInfo> selectBrandInfoListAll() {

        List<BrandInfo> brandInfos = brandInfoMapper.selectBrandInfoListAll();

        brandInfos.stream().peek(brandInfo -> {
            List<CategoryBrand> categoryBrandList = categoryBrandMapper.selectListByBrandInfo(brandInfo.getBrandId());
            List<Integer> coneIds = categoryBrandList.stream().map(CategoryBrand::getConeId).collect(Collectors.toList());
            brandInfo.setConeIds(coneIds);
        }).collect(Collectors.toList());

        return brandInfos;
    }

    @Override
    public List<BrandInfo> selectListBrandByConeId(Long coneId) {
        return brandInfoMapper.selectListBrandByConeId(coneId);
    }
}
